package com.heima.article.listener;

import com.alibaba.fastjson.JSON;
import com.heima.article.service.ApArticleConfigService;
import com.heima.common.constatns.WmNewsMessageConstants;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
@Slf4j
public class ArticlesDeleteListener {

    @Autowired
    private ApArticleConfigService apArticleConfigService;

    @KafkaListener(topics = WmNewsMessageConstants.WM_NEWS_DELETE_TOPIC)
    public void onMessage(String message){

        if (StringUtils.isNotBlank(message)) {
            log.info("消费者消费kafka消息 逻辑删除app端文章");

            Long articleId= JSON.parseObject(message, Long.class);

            apArticleConfigService.deleteByArticle(articleId);

        }
    }

}
